
public class MinMaxSpeler implements Speler {

	private boolean max;
	private String naam;
	private int expandedNodes;

	public MinMaxSpeler(String n)
	{
		this.naam = n;
		this.max = true;
	}
	
	public MinMaxSpeler()
	{
		this.naam = "Max";
		this.max = true;
	}
	
	public MinMaxSpeler(boolean isMax) {
		
	}
	
	@Override
	public String getNaam() {
		return this.naam;
	}
/*
	public ACTION makeDecision(STATE state) {
		expandedNodes = 0;
		ACTION result = null;
		double resultValue = Double.NEGATIVE_INFINITY;
		PLAYER player = game.getPlayer(state);
		for (ACTION action : game.getActions(state)) {
			double value = minValue(game.getResult(state, action), player);
			if (value > resultValue) {
				result = action;
				resultValue = value;
			}
		}
		return result;
	}
	*/
	

	@Override
	public int bepaalZet(Bord b) {
		expandedNodes = 0;
		int result;
		int resultValue = -1;
		
		for(int val : b.getActions()) {
			Bord c;
			c = b.deepCopy();
			c.doeZet(this, val);
			int value = minValue(c, this);
			if(value > resultValue) {
				result = val;
				resultValue = value;
			}	
		}		
		return resultValue;
	}

	public int minValue(Bord b, Speler s) { // returns an utility
		int value = 0;													// value
		expandedNodes++;
		
		if (b.isEndstate()) {
			value =  b.calculateValue(b);
		}
		else {
		value = Integer.MAX_VALUE;
			for (int val : b.getActions()) {
				Bord c;
				c = b.deepCopy();
				c.doeZet(this, val);
				value = Math.min(value,	maxValue(c, this));
			}
		}
		return value;
	}

	public int maxValue(Bord b, Speler s) { // returns an utility
		int value = 0;													// value
		expandedNodes++;
		
		if (b.isEndstate()) {
			value =  b.calculateValue(b);
		}
		else {
		value = Integer.MIN_VALUE;
			for (int val : b.getActions()) {
				Bord c;
				c = b.deepCopy();
				c.doeZet(this, val);
			
				value = Math.min(value, minValue(c, this));
			}
		}
		return value;
	}

	
	@Override
	public int doeZet(Bord b) {
		return bepaalZet(b);
	}
	
	
}
